import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

//引入阿里icon
import './assets/iconfont/iconfont.css'
//引入全局样式
import './assets/css/init.css'
//引入动画库

//注册全局组件
const app = createApp(App)
import PageView from "@/components/PageView.vue"
app.component('page-view', PageView)
import PageHeader from '@/components/PageHeader.vue'
app.component('page-header', PageHeader)

//注册一些vant中的全局组件  轻提示（弹窗提示）和懒加载
import { Toast, Lazyload } from 'vant';
//设置Toast在loading时，背景不可被点击
Toast.setDefaultOptions('loading', { forbidClick: true });
app.use(Toast);

app.use(Lazyload, {
    lazyComponent: true,
    loading: require("./assets/image/loading.gif"),
    error: require("./assets/image/error.jpeg")
});

// 写入mixin,全局挂载一个baseURL,写入长按指令
app.mixin({
    data() {
        return {
            BaseURL: "http://home.softeem.xin:9544"
        }
    }
}).directive('longpress', {
    mounted(el, bingding, vNode, oldVNode) {
        let timeout = bingding.arg || 500;
        let timeId = null;
        el.addEventListener('touchstart', event => {
            timeId = setTimeout(() => {
                bingding.value.call(vNode.context, event)
            }, timeout)
        })
        el.addEventListener('touchmove', event => {
            clearTimeout(timeId)
        })
        el.addEventListener('touchend', event => {
            clearTimeout(timeId)
        })
        el.addEventListener('touchcancel', event => {
            clearTimeout(timeId)
        })
    }
})

app.use(store).use(router).mount('#app')